<?php 

class BrandModel extends Model{
	public $table = 'brand';
	public $validate = array(
		array('bname','nonull','品牌名不能为空',2,3),
		array('sort','nonull','排序不能为空',2,3),
	);
	/**
	 * 自动完成
	 */
	 public $auto = array(
	 	//1.字段名 2.函数或者是方法名称 3.用什么方式处理 4.条件 5.时机
	 	array('sort','intval','function',2,3),
	 );
	public function addData(){
		if(!$this->create()) return FALSE;
		if($_FILES){
			if($_FILES['logo']['error'] != 4){
				//执行上传类
			 	$upload = new Upload();
				$files = $upload->upload();
				//如果上传 失败
				if(!$files){
					$this->error = $upload->error;
					return false;
				}
				//缩略处理******
				$img = new Image();
				$thumbPath = $img->thumb($files[0]['path'],"",80,80,5);  
				
				//$this->data 就是 添加要操作的数组，它里面有什么，add就会自动添加什么
				$this->data['logo'] = $thumbPath;
			}
		}
		return $this->add();
	}
	public function editDate($id){
	    if(!$this->create()) return FALSE;
		if($_FILES){
			if($_FILES['logo']['error'] != 4){
				//执行上传类
			 	$upload = new Upload();
				$files = $upload->upload();
				//如果上传 失败
				if(!$files){
					$this->error = $upload->error;
					return false;
				}
				//缩略处理******
				$img = new Image();
				$thumbPath = $img->thumb($files[0]['path'],"",80,80,5);  
				
				//$this->data 就是 添加要操作的数组，它里面有什么，add就会自动添加什么
				$this->data['logo'] = $thumbPath;
			}
		}
		return $this->where("bid={$id}")->update();
	}
}
